<?php 

class ClassController extends Controller{
	private $db;//对象
	public function __construct()
	{
		parent::__construct();	//子集有构造函数后父子的构造函数不能自动执行
		$this->db=new ClassModel;
	}
	public function index()
	{
		// p($this->db->limit('5')->where('cid>10')->find());
		$data=$this->db->getlist();
		$this->assign('data',$data);
		$this->display('index.html');
	}


	//添加班级
	public function add()
	{
		if (IS_POST) {
			if ($this->db->addClass($_POST)) {
				$this->success('添加成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}
		}else{
			$this->display('add.html');
		}
	}
	//更新班级
	public function update()
	{
		if (IS_POST) {
			if ($this->db->updateClass($_POST)) {
				$this->success('修改成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}	
		}else{
			$data =$this->db->where("cid={$_GET['cid']}")->find();
			$this->assign('filed',$data);
			$this->display('update.html');
		}
	}
	//删除班级
	public function delete()
	{
		if (empty($_GET['cid']))return false;
		if ($this->db->deleteClass($_GET)) {
			$this->success('删除成功',__CONTROLLER__);
		}else{
			$this->error($this->db->error);
		}
	}
}

 ?>